/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.alvin.xl.hlht.ui;

import org.alvin.mini_inject.annotations.MiniComponent;
import org.alvin.mini_inject.annotations.MiniInject;
import org.alvin.xl.hlht.client.HlhtClientDecodeSimulator;
import org.alvin.xl.hlht.client.HlhtClientSimulator;

/**
 * @author 86139
 */
@MiniComponent
public class DecodeFrame extends javax.swing.JFrame {

    @MiniInject
    private HlhtClientDecodeSimulator hlhtClientDecodeSimulator;
    @MiniInject
    private HlhtClientSimulator hlhtClientSimulator;

    /**
     * Creates new form DecodeFrame
     */
    public DecodeFrame() {
        initComponents();
        setTitle("互联互通协议解密-超锅锅专用-V0.1");
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        selInterface = new javax.swing.JComboBox<>();
        jButton2 = new javax.swing.JButton();
        jTabbedPane3 = new javax.swing.JTabbedPane();
        jScrollPane3 = new javax.swing.JScrollPane();
        txtEncodeConsole = new javax.swing.JEditorPane();
        jPanel2 = new javax.swing.JPanel();
        jTabbedPane2 = new javax.swing.JTabbedPane();
        jScrollPane2 = new javax.swing.JScrollPane();
        txtConsole = new javax.swing.JEditorPane();
        jButton1 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtSrcData = new javax.swing.JEditorPane();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("接口");

        selInterface.setModel(new javax.swing.DefaultComboBoxModel<>(new String[]
                { "1.查询Token", "2.获取站点信息", "3.获取充电价格", "4.启动充电", "5.停止充电", "6.获取订单实时数据", "7.获取站点状态信息" ,
                "8.查询运营商信息" , "9.设备认证", "10.站点统计" ,"11.请求充电状态"}));

        jButton2.setText("加密数据");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                try {
                    jButton2ActionPerformed(evt);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        });

        jScrollPane3.setViewportView(txtEncodeConsole);

        jTabbedPane3.addTab("控制台", jScrollPane3);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(selInterface, 0, 548, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(jButton2)
                .addGap(48, 48, 48))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane3)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(41, 41, 41)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(selInterface, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton2))
                .addGap(18, 18, 18)
                .addComponent(jTabbedPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 539, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("互联互通加密", jPanel1);

        jScrollPane2.setViewportView(txtConsole);

        jTabbedPane2.addTab("控制台", jScrollPane2);

        jButton1.setText("解密数据");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jScrollPane1.setViewportView(txtSrcData);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTabbedPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 771, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jButton1)))
                .addContainerGap())
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 771, Short.MAX_VALUE)
                    .addContainerGap()))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap(340, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jTabbedPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 258, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 317, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(304, Short.MAX_VALUE)))
        );

        jTabbedPane1.addTab("互联互通数据解密", jPanel2);

        getContentPane().add(jTabbedPane1, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        String srcData = this.txtSrcData.getText().trim();
        String distData = null;
        try {
            distData = this.hlhtClientDecodeSimulator.decode(srcData);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        this.txtConsole.setText(distData);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) throws Exception {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        int index = this.selInterface.getSelectedIndex() + 1;
        if(index == 1){
            String text = hlhtClientSimulator.queryToken().toJSONString();
            this.txtEncodeConsole.setText(text);
            return ;
        }
        if(index == 2){
            String text = hlhtClientSimulator.queryStation().toJSONString();
            this.txtEncodeConsole.setText(text);
            return ;
        }
        if(index == 3){
            String text = hlhtClientSimulator.queryPriceRule().toJSONString();
            this.txtEncodeConsole.setText(text);
            return ;
        }
        if(index == 4){
            String text = hlhtClientSimulator.startCharge().toJSONString();
            this.txtEncodeConsole.setText(text);
            return ;
        }
        if(index == 5){
            String text = hlhtClientSimulator.stopCharge().toJSONString();
            this.txtEncodeConsole.setText(text);
            return ;
        }
        if(index == 6){
            String text = hlhtClientSimulator.queryOrderStatus().toJSONString();
            this.txtEncodeConsole.setText(text);
            return ;
        }
        if(index == 7){
            String text = hlhtClientSimulator.queryStationStatus().toJSONString();
            this.txtEncodeConsole.setText(text);
            return ;
        }
        if(index == 8){
            String text = hlhtClientSimulator.queryOperatorInfo().toJSONString();
            this.txtEncodeConsole.setText(text);
            return ;
        }
        if(index == 9){
            String text = hlhtClientSimulator.queryEquipAuth().toJSONString();
            this.txtEncodeConsole.setText(text);
            return ;
        }
        if(index == 10){
            String text = hlhtClientSimulator.queryStationStats().toJSONString();
            this.txtEncodeConsole.setText(text);
            return ;
        }
        if(index == 11){
            String text = hlhtClientSimulator.queryFinishOrders().toJSONString();
            this.txtEncodeConsole.setText(text);
            return ;
        }

    }//GEN-LAST:event_jButton2ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTabbedPane jTabbedPane2;
    private javax.swing.JTabbedPane jTabbedPane3;
    private javax.swing.JComboBox<String> selInterface;
    private javax.swing.JEditorPane txtConsole;
    private javax.swing.JEditorPane txtEncodeConsole;
    private javax.swing.JEditorPane txtSrcData;
    // End of variables declaration//GEN-END:variables
}
